package im.vinci.server.feed.persistence;

import im.vinci.server.feed.domain.UserPlayTimeInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
/**
 * Created by mingjie on 17/2/18.
 */
@Repository
public interface UserPlayTimeInfoMapper {

    @Select("SELECT user_id,duration_time,create_time FROM user_play_time_info WHERE owner_id=#{user_id} AND create_time=#{date} ORDER BY duration_time DESC")
    List<UserPlayTimeInfo> select(@Param("user_id") long userId, @Param("date") Date date);

    @Insert({"<script>",
            "INSERT INTO user_play_time_info ",
            "(owner_id, user_id, duration_time, create_time) VALUES ",
            "<foreach item='item' index='index' collection='list' separator=','>",
            "(#{owner_id},#{item.userId}, #{item.durationTime}, #{item.createTime})",
            "</foreach>",
            "</script>"})
    int batchInsert(@Param("owner_id") long userId, @Param("list") List<UserPlayTimeInfo> list);
}
